package com.lancoo.cvas.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lancoo.cvas.entity.RuleTeachingClassProhibit;
import com.lancoo.cvas.entity.TeachingClassWeek;
import com.lancoo.cvas.mapper.TeachingClassWeekMapper;
import com.lancoo.cvas.pojo.common.Deleted;
import com.lancoo.cvas.pojo.common.ScheduleState;
import com.lancoo.cvas.pojo.dto.LockDto;
import com.lancoo.cvas.service.RuleTeachingClassProhibitService;
import com.lancoo.cvas.service.TeachingClassWeekService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;


@Service("teacheringClassWeekService")
public class TeachingClassWeekServiceImpl extends ServiceImpl<TeachingClassWeekMapper, TeachingClassWeek> implements TeachingClassWeekService {

    @Resource
    private RuleTeachingClassProhibitService ruleTeachingClassProhibitService;

    @Override
    public Boolean updateLocks(Integer isLocked, LockDto locks) {
        return baseMapper.updateLocks(isLocked, locks);
    }

    /**
     * @param tcIds:
     * @param unRange:
     * @param conflict:
     * @param deleted:
     * @Description: 获取排课有问题的教学班id
     * @Author: liufeng
     * @Date: 2024/1/8 19:34
     * @return:
     */
    @Override
    public List<Long> getUnScheduleTeachingClassIds(List<Long> tcIds, int unRange, int conflict, int deleted) {
        return baseMapper.getUnScheduleTeachingClassIds(tcIds, unRange, conflict, deleted);
    }

    @Override
    public List<TeachingClassWeek> getUnRanage(Integer taskId, Integer roomType, int deleted) {
        return baseMapper.getUnRange(taskId, roomType, deleted);
    }

    @Override
    public void removeUnSuit(Integer taskId) {
        List<Long> ids = ruleTeachingClassProhibitService.lambdaQuery()
                .eq(RuleTeachingClassProhibit::getTaskId, taskId)
                .eq(RuleTeachingClassProhibit::getFlag, 1)
                .eq(RuleTeachingClassProhibit::getDeleted, Deleted.NOT.getCode())
                .list()
                .stream().map(RuleTeachingClassProhibit::getTeachingClassId)
                .distinct().collect(Collectors.toList());
        baseMapper.removeUnSuit(taskId, ids, ScheduleState.UNSUITABLE.getCode(), ScheduleState.NORMAL.getCode());
    }

}